﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using StudioLib;
namespace StuCat.Controls
{
    public partial class AttributeEditor : UserControl
    {
        public Dictionary<String, object> Attrs { get; private set; }
        
        public AttributeEditor()
        {
            InitializeComponent();
            Attrs = new Dictionary<string, object>();
        }

        private void AttributeEditor_Load(object sender, EventArgs e)
        {
            foreach (StudioAttribute item in Studio.RegisteredAttributes)
            {
                listBox1.Items.Add(item.Name);
            }
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex == -1) return;

            groupBox1.Controls.Clear();

            StudioAttribute attr = Studio.RegisteredAttributes[listBox1.SelectedIndex];

            Control ctrl = null;
            if (attr.ValueType == typeof(bool))
            {
                ctrl = new CheckBox();
                ((CheckBox)ctrl).CheckedChanged += delegate { Attrs.Add(attr.Name, ((CheckBox)ctrl).Checked); };
            }
            if (attr.ValueType == typeof(int))
            {
                ctrl = new NumericUpDown();
            }
            if (attr.ValueType == typeof(string))
            {
                ctrl = new TextBox();
            }

            groupBox1.Controls.Add(ctrl);
        }
    }
}
